package com.ruoyi.hr.job.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.hr.job.domain.HrJob;
import com.ruoyi.hr.job.service.IHrJobService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 岗位Controller
 *
 * @author xzshan
 * @date 2020-07-09
 */
@Controller
@RequestMapping("/api/job")
public class HrJobController extends BaseController
{
    private String prefix = "api/job";

    @Autowired
    private IHrJobService hrJobService;

    @RequiresPermissions("api:job:view")
    @GetMapping()
    public String job()
    {
        return prefix + "/job";
    }

    /**
     * 查询岗位列表
     */
    @RequiresPermissions("api:job:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(HrJob hrJob)
    {
        startPage();
        List<HrJob> list = hrJobService.selectHrJobList(hrJob);
        return getDataTable(list);
    }

    /**
     * 导出岗位列表
     */
    @RequiresPermissions("api:job:export")
    @Log(title = "岗位", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(HrJob hrJob)
    {
        List<HrJob> list = hrJobService.selectHrJobList(hrJob);
        ExcelUtil<HrJob> util = new ExcelUtil<HrJob>(HrJob.class);
        return util.exportExcel(list, "job");
    }

    /**
     * 新增岗位
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存岗位
     */
    @RequiresPermissions("api:job:add")
    @Log(title = "岗位", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(HrJob hrJob)
    {
        return toAjax(hrJobService.insertHrJob(hrJob));
    }

    /**
     * 修改岗位
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        HrJob hrJob = hrJobService.selectHrJobById(id);
        mmap.put("hrJob", hrJob);
        return prefix + "/edit";
    }

    /**
     * 修改保存岗位
     */
    @RequiresPermissions("api:job:edit")
    @Log(title = "岗位", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(HrJob hrJob)
    {
        return toAjax(hrJobService.updateHrJob(hrJob));
    }

    /**
     * 删除岗位
     */
    @RequiresPermissions("api:job:remove")
    @Log(title = "岗位", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(hrJobService.deleteHrJobByIds(ids));
    }
}
